package com.example.actordemo1.becom;

import akka.actor.AbstractActor;
import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.Props;
import akka.japi.Procedure;
import scala.Option;

public class BecomActor extends AbstractActor {



    @Override
    public Receive createReceive() {
        return receiveBuilder().matchAny(o->{
            System.out.println("接收消息"+o);
            getContext().become(beocomM(o+"1111"));
        }).build();
    }

    private Receive beocomM(String msg) {
        return receiveBuilder().matchAny(o->{
            System.out.println(o+"aaaaaaa");
            System.out.println(msg);
            if(o.equals("222+")){
                getContext().unbecome();
            }
        }).build();
    }

    public static void main(String[] args) {
        ActorSystem actorSystem = ActorSystem.create("sys");
        ActorRef becomActor = actorSystem.actorOf(Props.create(BecomActor.class), "becomActor");
        becomActor.tell("111+",ActorRef.noSender());
        becomActor.tell("222+",ActorRef.noSender());
        becomActor.tell("333+",ActorRef.noSender());

    }
}
